package com.ruoyi.business.utils;

import lombok.extern.slf4j.Slf4j;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.Point;
import org.opengis.feature.Property;
import org.opengis.feature.simple.SimpleFeature;

import java.util.Collection;
import java.util.Iterator;

@Slf4j
public class AnalysisUtil {
    public static void readProperty(SimpleFeature simpleFeature) {
        if (simpleFeature != null) {
            Collection<Property> properties = simpleFeature.getProperties();
            Iterator<Property> iterator = properties.iterator();
            int index = 0;
            while (iterator.hasNext()) {
                Property property = iterator.next();
                //kml拿到属性值会有自带的9个属性
                if (index++ > 8) {
                    log.info("GeoJSONReader解析geojson -->> 属性名：【{}】，属性值：【{}】，属性类型：【{}】", property.getName().toString(),
                            property.getValue(), property.getType().getBinding());
                }
            }
            Object defaultGeometry = simpleFeature.getDefaultGeometry();
            //wkt格式geometry
            Geometry geometry = (Geometry) defaultGeometry;
            if (geometry != null) {
                Point point = geometry.getInteriorPoint();
                System.out.println("=====" + point.getX() + ",  " + point.getY());
            }

            log.info("wkt格式geometry：{}", geometry);
        }
    }
}
